//
//  GRUserAction.m
//  YC_GRice
//
//  Created by Feng Liu on 2018/9/1.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRUserAction.h"
#import "GRMyBillModel.h"
#import "GRCollectionModel.h"
#import "GRCollectCommonModel.h"
#import "GRXCouponsModel.h"
@implementation GRUserAction

+ (void)getMyCollectionWithParamer:(NSDictionary *)paramer isInstallment:(BOOL)isInstallment completionHandler:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@v1/collection/list",GRiceAPI];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            NSArray *array = responseObject[@"dataList"];
            NSMutableArray *collections = [NSMutableArray array];
            if (isInstallment) {
                for (NSDictionary *dic in array) {
                    GRCollectionModel *model = [GRCollectionModel yy_modelWithDictionary:dic];
                    [collections addObject:model];
                }
            }else {
                for (NSDictionary *dic in array) {
                    GRCollectCommonModel *model = [GRCollectCommonModel yy_modelWithDictionary:dic];
                    [collections addObject:model];
                }
            }
            completionHandler(YES, collections, nil);
        }else {
            completionHandler(NO, nil, error);
        }
    }];
}


+ (void)getHaveBeenToShopWithParamer:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@onePay/history",GRDeliveryAPI];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            NSArray *array = responseObject[@"dataList"];
            NSMutableArray *shopList = [NSMutableArray array];
            if (Array(array)) {
                for (NSDictionary *dic in array) {
                    GRCollectCommonModel *model = [GRCollectCommonModel yy_modelWithDictionary:dic];
                    [shopList addObject:model];
                }
            }
            completionHandler(YES, shopList, nil);
        }else {
            completionHandler(NO, nil, error);
        }
    }];
}

+ (void)getMyBillListWithParamer:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@onePayOrder/list",GRDeliveryAPI];
    
    [RequestManager MembershipRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            NSArray *array = responseObject[@"dataList"];
            NSMutableArray *billList = [NSMutableArray array];
            if (Array(array)) {
                for (NSDictionary *dic in array) {
                    GRMyBillModel *model = [GRMyBillModel yy_modelWithDictionary:dic];
                    [billList addObject:model];
                }
            }
            completionHandler(YES, billList, nil);
        }else {
            completionHandler(NO, nil, error);
        }
    }];
}

+(void)getCouponsList:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler{
    NSString * url = [NSString stringWithFormat:@"%@v1/voucher/shardBountyAndVoucher",GRiceAPI];
    [RequestManager MembershipRequestWithURLString:url Method:GR_GET Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            NSLog(@"%@",responseObject);
           
                completionHandler(YES, responseObject, nil);
            
        }else{
                completionHandler(NO, nil, error);
        }
    }];
    
    
}


@end
